/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import battleship.ship.DirectionEnum;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Scanner;

/**
 *
 * @author ali
 */
public class InputTaker {

    public static List<Integer> takeInput(String... args) {

        List<Integer> xy = new ArrayList<Integer>();
        try {
            printArgs(args);
            Scanner s = new Scanner(System.in);
            int x = s.nextInt();
            int y = s.nextInt();

            xy.add(new Integer(x));
            xy.add(new Integer(y));

        } catch (InputMismatchException e) {

            String hint = "Only integer values allowed";
            MsgPrinter.warn(hint);
            return takeInput();

        }

        return xy;
    }

    public static DirectionEnum readDirection(String ... args){
        Integer readInt = null;
        try {
            printArgs(args);
            Scanner s = new Scanner(System.in);
            int x = s.nextInt();
            readInt = new Integer(x);
        } catch (InputMismatchException e) {
            String hint = "Only integer values allowed";
            MsgPrinter.warn(hint);
            return readDirection(args);
        }
        DirectionEnum dir = DirectionEnum.toDirectionEnum(readInt);
        return dir;
    }

    private static void printArgs(String[] args) {
        for(String arg:args){
            MsgPrinter.print(arg);
        }
    }
}
